package model.os.pagereplacement;

import java.util.LinkedList;

import model.os.PageTableEntry;

public class LRU implements PageReplacementStrategy {

	private LinkedList<PageTableEntry> queue;

	public LRU() {
		queue = new LinkedList<PageTableEntry>();
	}

	public int getPageToReplace() {
		PageTableEntry entry = queue.removeFirst();
		entry.setValid(false);
		return entry.getPageFrameNumber();
	}

	public String getName() {
		return "LRU";
	}

	public void addPage(PageTableEntry entry) {
		queue.add(entry);
	}

	public void refferenced(PageTableEntry entry) {
		if (queue.contains(entry)) {
			queue.remove(entry);
			queue.addLast(entry);
		}
	}
}
